package test4_14.demo01;

import java.util.Random;

public class Homework22_5_2 implements Runnable{


    static Random random = new Random();
    private String filename;

    public Homework22_5_2(String filename) {
        this.filename = filename;
    }

    public void run() {
        try {
            for (int i = 0; i <= 100; i++) {
                System.out.println(filename + "已下载：" + i + "%");
                Thread.sleep(random.nextInt(200) + 100);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

class main1{
    public static void main(String[] args) throws InterruptedException {

        System.out.println("下载开始");

        Thread file1 = new Thread(new Homework22_5_2("book1"));
        Thread file2 = new Thread(new Homework22_5_2("book2"));
        Thread file3 = new Thread(new Homework22_5_2("book3"));

        file1.start();
        file2.start();
        file3.start();

        file1.join();
        file2.join();
        file3.join();

        System.out.println("下载结束");
    }
}


